
<?php 
//这里仅以特定图片格式举例，本应动态获取 
$url = 'upload/img' . time() . '.jpg'; 
if (move_uploaded_file($_FILES['uploadphoto']['tmp_name'], $url)) { 
  //删除之前的图片 
  $_POST['photo'] !== '' && unlink($_POST['photo']); 
?> 
<html> 
<head> 
<body onLoad="doneLoading(parent, '<?=$url?>')"> 
</body> 
</html> 
<script type="text/javascript">
//在页面上显示刚刚上传成功的图像 
function doneLoading(theFrame, url) { 
  var oDiv = theFrame.document.getElementById('displayphoto'); 
  oDiv.innerHTML = '<img src="' + url + '" mce_src="' + url + '" alt="上传头像" />'; 
  theFrame.document.getElementById('photo').value = url; 
} 
<script> 
<?php 
}
?>